<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="cnsyear Java 分布式 程序员">





  <link rel="alternate" href="/atom.xml" title="CNSYEAR BLOG'S" type="application/atom+xml">






<meta name="description" content="I MISS YOU.">
<meta property="og:type" content="website">
<meta property="og:title" content="CNSYEAR BLOG&#39;S">
<meta property="og:url" content="https://cnsyear.com/page/7/index.html">
<meta property="og:site_name" content="CNSYEAR BLOG&#39;S">
<meta property="og:description" content="I MISS YOU.">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="CNSYEAR BLOG&#39;S">
<meta name="twitter:description" content="I MISS YOU.">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://cnsyear.com/page/7/">





  <title>CNSYEAR BLOG'S</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband">
	
		<a href="https://github.com/cnsyear" target="_blank" class="github-corner" aria-label="Follow me on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
	
		
	</div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">CNSYEAR BLOG'S</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">心有猛虎，细嗅蔷薇</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            时间轴
          </a>
        </li>
      
        
        <li class="menu-item menu-item-friends">
          <a href="/friends/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-globe"></i> <br>
            
            朋友们
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://cnsyear.com/2018/01/11/Windows上安装RabbitMQ/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="趙小傑~～">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="CNSYEAR BLOG'S">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/01/11/Windows上安装RabbitMQ/" itemprop="url">Windows上安装RabbitMQ</a></h1>
        

        <div class="post-meta">
		 
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-11T21:57:33+08:00">
                2018-01-11
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/RabbitMQ/" itemprop="url" rel="index">
                    <span itemprop="name">RabbitMQ</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>Windows上安装RabbitMQ</p>
</blockquote>
<h4 id="一、windows安装Erlang和RabbitMQ"><a href="#一、windows安装Erlang和RabbitMQ" class="headerlink" title="一、windows安装Erlang和RabbitMQ"></a>一、windows安装Erlang和RabbitMQ</h4><h5 id="先安装Erlang"><a href="#先安装Erlang" class="headerlink" title="先安装Erlang"></a>先安装Erlang</h5><ul>
<li>Erlang/OTP 20.3下载地址：<a href="http://erlang.org/download/otp_win64_20.3.exe" target="_blank" rel="noopener">http://erlang.org/download/otp_win64_20.3.exe</a></li>
<li>Erlang/OTP其它版本下载地址：<a href="http://www.erlang.org/downloads" target="_blank" rel="noopener">http://www.erlang.org/downloads</a></li>
<li>配置Erlang环境变量并在path后面追加 %ERLANG_HOME%\bin </li>
<li>erl -v回车检查是否配置成功</li>
</ul>
<h5 id="再安装RabbitMQ-Server"><a href="#再安装RabbitMQ-Server" class="headerlink" title="再安装RabbitMQ Server"></a>再安装RabbitMQ Server</h5><ul>
<li>RabbitMQ Server 3.7.4下载地址：<br><a href="https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.4/rabbitmq-server-3.7.4.exe" target="_blank" rel="noopener">https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.4/rabbitmq-server-3.7.4.exe</a></li>
<li><p>RabbitMQ其它版本下载地址：<a href="https://www.rabbitmq.com/download.html" target="_blank" rel="noopener">https://www.rabbitmq.com/download.html</a></p>
<p>百度云下载链接：<a href="https://pan.baidu.com/s/18Zpeg7BpePTFs7rxQPoigw" target="_blank" rel="noopener">https://pan.baidu.com/s/18Zpeg7BpePTFs7rxQPoigw</a> 密码：d62x</p>
</li>
</ul>
<h4 id="二、启动RabbitMQ-Server"><a href="#二、启动RabbitMQ-Server" class="headerlink" title="二、启动RabbitMQ Server"></a>二、启动RabbitMQ Server</h4><p>RabbitMQ Server安装之后，会自动注册为windows服务，并以默认配置启动起来</p>
<p><img src="https://zj820382480.gitee.io/youdaoyun/image/20180709140141198.png" alt="image"></p>
<h4 id="三、安装RabbitMQ管理页面（如有问题请重启一下电脑再安装！！！）"><a href="#三、安装RabbitMQ管理页面（如有问题请重启一下电脑再安装！！！）" class="headerlink" title="三、安装RabbitMQ管理页面（如有问题请重启一下电脑再安装！！！）"></a>三、安装RabbitMQ管理页面（如有问题请重启一下电脑再安装！！！）</h4><p>1.开启Web管理插件<br>进入rabbitmq安装目录的sbin目录，在此打开CMD命令窗口，执行以下命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rabbitmq-plugins enable rabbitmq_management</span><br></pre></td></tr></table></figure>
<p>出现如下提示，说明web管理插件安装成功</p>
<p><img src="https://zj820382480.gitee.io/youdaoyun/image/20180709140443957.png" alt="image"></p>
<p>然后重新启动RabbitMQ 服务，打开浏览器并访问：<a href="http://localhost:15672" target="_blank" rel="noopener">http://localhost:15672</a>，并使用默认用户guest登录，密码也为guest，即可进入管理界面</p>
<h4 id="Rabbit安装问题"><a href="#Rabbit安装问题" class="headerlink" title="Rabbit安装问题"></a>Rabbit安装问题</h4><h5 id="Rabbit安装问题一-：计算机主机名不能有中文"><a href="#Rabbit安装问题一-：计算机主机名不能有中文" class="headerlink" title="Rabbit安装问题一 ：计算机主机名不能有中文"></a>Rabbit安装问题一 ：计算机主机名不能有中文</h5><p>注：erlang有个很坑的地方，你的计算机主机名不能有中文，不是安装会有问题。会有如下报错：</p>
<p><img src="https://zj820382480.gitee.io/youdaoyun/image/20180717203411418.png" alt="image"></p>
<h5 id="Rabbit安装问题二-：-安装完卸载在安装出现的问题-could-not-set-correct-interactive-mode"><a href="#Rabbit安装问题二-：-安装完卸载在安装出现的问题-could-not-set-correct-interactive-mode" class="headerlink" title="Rabbit安装问题二 ： 安装完卸载在安装出现的问题 could not set correct interactive mode"></a>Rabbit安装问题二 ： 安装完卸载在安装出现的问题 could not set correct interactive mode</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Installing RabbitMQ service... </span><br><span class="line">RabbitMQ service is already present - only updating service parameters</span><br><span class="line">C:\rabbitmq\erl9.3\erts-9.3\bin\erlsrv: Warning, could not set correct interactive mode. RabbitMQ</span><br><span class="line">Error: 戮盲卤煤脦脼脨搂隆拢</span><br><span class="line">C:\rabbitmq\erl9.3\erts-9.3\bin\erlsrv: Warning, could not set correct service description (comment) RabbitMQError: 戮盲卤煤脦脼脨搂隆拢</span><br><span class="line">Starting RabbitMQ service...</span><br><span class="line">服务名无效。</span><br><span class="line">请键入 NET HELPMSG 2185 以获得更多的帮助。</span><br><span class="line">Copy failed</span><br></pre></td></tr></table></figure>
<p>解决方法：<br>删除注册表  HKLM/SOFTWARE/Ericsson/Erlang/ErlSrv 下安装的RabbitMQ</p>
<p><img src="https://zj820382480.gitee.io/youdaoyun/image/20180719204603395.png" alt="image"></p>

          
        
      
    </div>
    
    
    

	<div>
		
	</div>
	<div>
		
	</div>
    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://cnsyear.com/2018/01/11/IntelliJ IDEA设置自动导入包/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="趙小傑~～">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="CNSYEAR BLOG'S">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/01/11/IntelliJ IDEA设置自动导入包/" itemprop="url">IntelliJ IDEA设置自动导入包</a></h1>
        

        <div class="post-meta">
		 
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-11T21:52:59+08:00">
                2018-01-11
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/IntelliJ-IDEA/" itemprop="url" rel="index">
                    <span itemprop="name">IntelliJ IDEA</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>IntelliJ IDEA可以自动优化导入包，但是有多个同名的类位于不同的包时，需要自己手动使用Alt + Enter进行导入。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">- Settings→Editor→General→Auto Import</span><br><span class="line">- 选中Optimize imports on the fly和Add unambiguous imports on the fly</span><br><span class="line">	- Optimize imports on the fly：自动去掉一些没有用到的包</span><br><span class="line">	- Add unambiguous imports on the fly：自动帮我们优化导入的包</span><br></pre></td></tr></table></figure>
<p><img src="https://zj820382480.gitee.io/youdaoyun/image/24356789fasghd.png" alt="image"></p>

          
        
      
    </div>
    
    
    

	<div>
		
	</div>
	<div>
		
	</div>
    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://cnsyear.com/2017/07/13/java多音字处理/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="趙小傑~～">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="CNSYEAR BLOG'S">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/07/13/java多音字处理/" itemprop="url">java多音字处理</a></h1>
        

        <div class="post-meta">
		 
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-07-13T17:35:25+08:00">
                2017-07-13
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/" itemprop="url" rel="index">
                    <span itemprop="name">java</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/pinyin4j/" itemprop="url" rel="index">
                    <span itemprop="name">pinyin4j</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>java多音字处理</p>
</blockquote>
<h4 id="问题背景："><a href="#问题背景：" class="headerlink" title="问题背景："></a>问题背景：</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">查询列表中有时候需要按照中文首字母进行排序,这时候一般需要将字段转为拼音进行排序最为稳妥。</span><br><span class="line"> 例如：姓名按照汉字的拼音排序、省份按照拼音排序</span><br></pre></td></tr></table></figure>
<h4 id="解决方案一：直接使用mysql语句进行排序（适合简单的不复杂的可以）"><a href="#解决方案一：直接使用mysql语句进行排序（适合简单的不复杂的可以）" class="headerlink" title="解决方案一：直接使用mysql语句进行排序（适合简单的不复杂的可以）"></a>解决方案一：直接使用mysql语句进行排序（适合简单的不复杂的可以）</h4><p>在MySQL数据库中使用UTF-8的编码进行排序会出现不按照中文拼音的顺序排序<br>解决这个问题的方案是把编码重新设定为<strong><em>GBK或者GB2312</em></strong><br>但是问题又来了，数据库重设编码实在是个大问题，显然不能这样使用convert()这个函数可以实现临时编码并且解决问题</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">SQL语句：</span><br><span class="line">正序： </span><br><span class="line">select * <span class="function">from table_name ORDER BY <span class="title">CONVERT</span><span class="params">(name USING gbk)</span></span>;</span><br><span class="line">倒序：</span><br><span class="line">select * <span class="function">from  table_name ORDER BY <span class="title">CONVERT</span><span class="params">(name USING gb2312)</span> desc</span></span><br></pre></td></tr></table></figure>
<h5 id="注意："><a href="#注意：" class="headerlink" title="注意："></a>注意：</h5><p><img src="https://zj820382480.gitee.io/youdaoyun/image/TIM截图20190713172013.png" alt="image"></p>
<h4 id="解决方案二：使用pinyin4j这个jar将汉字转为拼音，再进行compareTo"><a href="#解决方案二：使用pinyin4j这个jar将汉字转为拼音，再进行compareTo" class="headerlink" title="解决方案二：使用pinyin4j这个jar将汉字转为拼音，再进行compareTo"></a>解决方案二：使用pinyin4j这个jar将汉字转为拼音，再进行compareTo</h4><h5 id="1-PinyinDuoYinziUtil工具类"><a href="#1-PinyinDuoYinziUtil工具类" class="headerlink" title="1.PinyinDuoYinziUtil工具类"></a>1.PinyinDuoYinziUtil工具类</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.highset;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.FileNotFoundException;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStreamReader;</span><br><span class="line"><span class="keyword">import</span> java.io.UnsupportedEncodingException;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.Arrays;</span><br><span class="line"><span class="keyword">import</span> java.util.Collections;</span><br><span class="line"><span class="keyword">import</span> java.util.Comparator;</span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;</span><br><span class="line"><span class="keyword">import</span> net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;</span><br><span class="line"><span class="keyword">import</span> net.sourceforge.pinyin4j.format.HanyuPinyinToneType;</span><br><span class="line"><span class="keyword">import</span> net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;</span><br><span class="line"><span class="keyword">import</span> net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &lt;b&gt;类描述：多音字排序工具类&lt;/b&gt;&lt;br/&gt;</span></span><br><span class="line"><span class="comment"> * &lt;b&gt;类名称：&lt;/b&gt;PinyinDuoYinziUtil.java&lt;br/&gt;</span></span><br><span class="line"><span class="comment"> * &lt;b&gt;创建人：&lt;/b&gt;jie.zhao&lt;br/&gt;</span></span><br><span class="line"><span class="comment"> * &lt;b&gt;创建时间：&lt;/b&gt;2017年10月16日&lt;br/&gt;</span></span><br><span class="line"><span class="comment"> * &lt;b&gt;备注：&lt;/b&gt;&lt;br/&gt;</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0.0&lt;br/&gt;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">PinyinDuoYinziUtil</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">private</span> <span class="keyword">static</span> Map&lt;String, List&lt;String&gt;&gt; pinyinMap = <span class="keyword">new</span> HashMap&lt;String, List&lt;String&gt;&gt;();</span><br><span class="line">	</span><br><span class="line">	<span class="comment">/**</span></span><br><span class="line"><span class="comment">	 * 静态代码块 --&gt;加载字典文件 </span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="keyword">static</span> &#123;</span><br><span class="line">		<span class="keyword">try</span> &#123;</span><br><span class="line">			initPinyin(<span class="string">"dict.txt"</span>);<span class="comment">// 这是自定义字典文件</span></span><br><span class="line">		&#125; <span class="keyword">catch</span> (FileNotFoundException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125; <span class="keyword">catch</span> (UnsupportedEncodingException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">/**</span></span><br><span class="line"><span class="comment">	 * &lt;b&gt;Description:主程序&lt;/b&gt;&lt;br&gt; </span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@param</span> args</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@throws</span> FileNotFoundException</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@throws</span> UnsupportedEncodingException</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@Note</span></span></span><br><span class="line"><span class="comment">	 * &lt;b&gt;Author:&lt;/b&gt;Jie.Zhao&lt;/a&gt;</span></span><br><span class="line"><span class="comment">	 * &lt;br&gt;&lt;b&gt;Date:&lt;/b&gt; 2017年12月1日 下午5:21:10</span></span><br><span class="line"><span class="comment">	 * &lt;br&gt;&lt;b&gt;Version:&lt;/b&gt; 1.0</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> FileNotFoundException, UnsupportedEncodingException </span>&#123;</span><br><span class="line">		List&lt;String&gt; list = <span class="keyword">new</span> ArrayList&lt;String&gt;();</span><br><span class="line">		list.add(<span class="string">"浙江"</span>);</span><br><span class="line">		list.add(<span class="string">"北京"</span>);</span><br><span class="line">		list.add(<span class="string">"重庆"</span>);</span><br><span class="line">		list.add(<span class="string">"云南"</span>);</span><br><span class="line">		list.add(<span class="string">"和"</span>);</span><br><span class="line">		list.add(<span class="string">"天津"</span>);</span><br><span class="line">		System.out.println(<span class="string">"排序前："</span>+list);</span><br><span class="line">		Collections.sort(list, <span class="keyword">new</span> Comparator&lt;String&gt;() &#123;</span><br><span class="line">			<span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">compare</span><span class="params">(String o1, String o2)</span> </span>&#123;</span><br><span class="line">				<span class="keyword">return</span> getPinYin(o1).compareTo(getPinYin(o2));</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;);</span><br><span class="line">		System.out.println(<span class="string">"排序后："</span>+list);</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line">		</span><br><span class="line">	<span class="comment">/**</span></span><br><span class="line"><span class="comment">	 * &lt;b&gt;Description: 这是核心方法&lt;/b&gt;&lt;br&gt; </span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@param</span> chinese</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@Note</span></span></span><br><span class="line"><span class="comment">	 * &lt;b&gt;Author:&lt;/b&gt;Jie.Zhao&lt;/a&gt;</span></span><br><span class="line"><span class="comment">	 * &lt;br&gt;&lt;b&gt;Date:&lt;/b&gt; 2017年12月1日 下午5:22:05</span></span><br><span class="line"><span class="comment">	 * &lt;br&gt;&lt;b&gt;Version:&lt;/b&gt; 1.0</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">getPinYin</span><span class="params">(String chinese)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">char</span>[] arr = <span class="keyword">null</span>;</span><br><span class="line">		arr = chinese.toCharArray();</span><br><span class="line">		String[] results = <span class="keyword">new</span> String[arr.length];</span><br><span class="line">		HanyuPinyinOutputFormat format = <span class="keyword">new</span> HanyuPinyinOutputFormat();</span><br><span class="line"></span><br><span class="line">		format.setCaseType(HanyuPinyinCaseType.LOWERCASE);</span><br><span class="line">		format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);</span><br><span class="line">		format.setVCharType(HanyuPinyinVCharType.WITH_V);</span><br><span class="line">		StringBuffer pinyin = <span class="keyword">new</span> StringBuffer();</span><br><span class="line">		String result = <span class="string">""</span>;</span><br><span class="line">		<span class="keyword">try</span> &#123;</span><br><span class="line">			<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; arr.length; i++) &#123;</span><br><span class="line">				<span class="keyword">char</span> ch = arr[i];</span><br><span class="line">				<span class="comment">// 判断是否为汉字字符</span></span><br><span class="line">				<span class="keyword">if</span> (java.lang.Character.toString(ch).matches(<span class="string">"[\\u4E00-\\u9FA5]+"</span>)) &#123;</span><br><span class="line">					results = net.sourceforge.pinyin4j.PinyinHelper.toHanyuPinyinStringArray(ch, format);</span><br><span class="line">					<span class="keyword">int</span> len = results.length;</span><br><span class="line"></span><br><span class="line">					<span class="keyword">if</span> (len == <span class="number">1</span>) &#123; <span class="comment">// 不是多音字</span></span><br><span class="line">						result = results[<span class="number">0</span>];</span><br><span class="line">					&#125; <span class="keyword">else</span> <span class="keyword">if</span> (results[<span class="number">0</span>].equals(results[<span class="number">1</span>])) &#123;<span class="comment">// 非多音字 有多个音，取第一个</span></span><br><span class="line">						result = results[<span class="number">0</span>];</span><br><span class="line">					&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">						<span class="comment">// 多音字</span></span><br><span class="line">						<span class="keyword">int</span> length = chinese.length();</span><br><span class="line">						<span class="keyword">boolean</span> flag = <span class="keyword">false</span>;</span><br><span class="line">						String s = <span class="keyword">null</span>;</span><br><span class="line">						List&lt;String&gt; keyList = <span class="keyword">null</span>;</span><br><span class="line">						<span class="keyword">for</span> (<span class="keyword">int</span> x = <span class="number">0</span>; x &lt; len; x++) &#123;</span><br><span class="line">							String py = results[x];</span><br><span class="line">							<span class="keyword">if</span> (py.contains(<span class="string">"u:"</span>)) &#123; <span class="comment">// 过滤 u:</span></span><br><span class="line">								py = py.replace(<span class="string">"u:"</span>, <span class="string">"v"</span>);</span><br><span class="line">								<span class="comment">// System.out.println("filter u:" + py);</span></span><br><span class="line">							&#125;</span><br><span class="line">							keyList = pinyinMap.get(py);</span><br><span class="line">							<span class="keyword">if</span> (i + <span class="number">3</span> &lt;= length) &#123; <span class="comment">// 后向匹配2个汉字 大西洋</span></span><br><span class="line">								s = chinese.substring(i, i + <span class="number">3</span>);</span><br><span class="line">								<span class="keyword">if</span> (keyList != <span class="keyword">null</span> &amp;&amp; (keyList.contains(s))) &#123;</span><br><span class="line">									<span class="comment">// System.out.println("last 2 &gt; " + py);</span></span><br><span class="line">									result = py;</span><br><span class="line">									flag = <span class="keyword">true</span>;</span><br><span class="line">									<span class="keyword">break</span>;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line"></span><br><span class="line">							<span class="keyword">if</span> (i + <span class="number">2</span> &lt;= length) &#123; <span class="comment">// 后向匹配 1个汉字 大西</span></span><br><span class="line">								s = chinese.substring(i, i + <span class="number">2</span>);</span><br><span class="line">								<span class="keyword">if</span> (keyList != <span class="keyword">null</span> &amp;&amp; (keyList.contains(s))) &#123;</span><br><span class="line">									<span class="comment">// System.out.println("last 1 &gt; " + py);</span></span><br><span class="line">									result = py;</span><br><span class="line">									flag = <span class="keyword">true</span>;</span><br><span class="line">									<span class="keyword">break</span>;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line"></span><br><span class="line">							<span class="keyword">if</span> ((i - <span class="number">2</span> &gt;= <span class="number">0</span>) &amp;&amp; (i + <span class="number">1</span> &lt;= length)) &#123; <span class="comment">// 前向匹配2个汉字 龙固大</span></span><br><span class="line">								s = chinese.substring(i - <span class="number">2</span>, i + <span class="number">1</span>);</span><br><span class="line">								<span class="keyword">if</span> (keyList != <span class="keyword">null</span> &amp;&amp; (keyList.contains(s))) &#123;</span><br><span class="line">									<span class="comment">// System.out.println("before 2 &lt; " + py);</span></span><br><span class="line">									result = py;</span><br><span class="line">									flag = <span class="keyword">true</span>;</span><br><span class="line">									<span class="keyword">break</span>;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line"></span><br><span class="line">							<span class="keyword">if</span> ((i - <span class="number">1</span> &gt;= <span class="number">0</span>) &amp;&amp; (i + <span class="number">1</span> &lt;= length)) &#123; <span class="comment">// 前向匹配1个汉字 固大</span></span><br><span class="line">								s = chinese.substring(i - <span class="number">1</span>, i + <span class="number">1</span>);</span><br><span class="line">								<span class="keyword">if</span> (keyList != <span class="keyword">null</span> &amp;&amp; (keyList.contains(s))) &#123;</span><br><span class="line">									<span class="comment">// System.out.println("before 1 &lt; " + py);</span></span><br><span class="line">									result = py;</span><br><span class="line">									flag = <span class="keyword">true</span>;</span><br><span class="line">									<span class="keyword">break</span>;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line"></span><br><span class="line">							<span class="keyword">if</span> ((i - <span class="number">1</span> &gt;= <span class="number">0</span>) &amp;&amp; (i + <span class="number">2</span> &lt;= length)) &#123; <span class="comment">// 前向1个，后向1个 固大西</span></span><br><span class="line">								s = chinese.substring(i - <span class="number">1</span>, i + <span class="number">2</span>);</span><br><span class="line">								<span class="keyword">if</span> (keyList != <span class="keyword">null</span> &amp;&amp; (keyList.contains(s))) &#123;</span><br><span class="line">									<span class="comment">// System.out.println("before last 1 &lt;&gt; " + py);</span></span><br><span class="line">									result = py;</span><br><span class="line">									flag = <span class="keyword">true</span>;</span><br><span class="line">									<span class="keyword">break</span>;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">						&#125;</span><br><span class="line"></span><br><span class="line">						<span class="keyword">if</span> (!flag) &#123; <span class="comment">// 都没有找到，匹配默认的 读音 大</span></span><br><span class="line">							s = String.valueOf(ch);</span><br><span class="line">							<span class="keyword">for</span> (<span class="keyword">int</span> x = <span class="number">0</span>; x &lt; len; x++) &#123;</span><br><span class="line">								String py = results[x];</span><br><span class="line">								<span class="keyword">if</span> (py.contains(<span class="string">"u:"</span>)) &#123; <span class="comment">// 过滤 u:</span></span><br><span class="line">									py = py.replace(<span class="string">"u:"</span>, <span class="string">"v"</span>);</span><br><span class="line">									<span class="comment">// System.out.println("filter u:");</span></span><br><span class="line">								&#125;</span><br><span class="line">								keyList = pinyinMap.get(py);</span><br><span class="line"></span><br><span class="line">								<span class="keyword">if</span> (keyList != <span class="keyword">null</span> &amp;&amp; (keyList.contains(s))) &#123;</span><br><span class="line">									<span class="comment">// System.out.println("default = " + py);</span></span><br><span class="line">									result = py;<span class="comment">// 拼音首字母 大写</span></span><br><span class="line">									<span class="keyword">break</span>;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">						&#125;</span><br><span class="line">					&#125;</span><br><span class="line">					pinyin.append(result);</span><br><span class="line">				&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">					pinyin.append(java.lang.Character.toString(arr[i]));</span><br><span class="line"></span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">return</span> pinyin.toString();</span><br><span class="line">		&#125; <span class="keyword">catch</span> (BadHanyuPinyinOutputFormatCombination e1) &#123;</span><br><span class="line">			e1.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="comment">// System.out.println(pinyin.toString());</span></span><br><span class="line">		<span class="keyword">return</span> pinyin.toString();</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">/**</span></span><br><span class="line"><span class="comment">	 * &lt;b&gt;Description:初始化 所有的多音字词组&lt;/b&gt;&lt;br&gt; </span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@param</span> filePath</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@throws</span> FileNotFoundException</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@throws</span> UnsupportedEncodingException</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@Note</span></span></span><br><span class="line"><span class="comment">	 * &lt;b&gt;Author:&lt;/b&gt;Jie.Zhao&lt;/a&gt;</span></span><br><span class="line"><span class="comment">	 * &lt;br&gt;&lt;b&gt;Date:&lt;/b&gt; 2017年12月1日 下午5:22:22</span></span><br><span class="line"><span class="comment">	 * &lt;br&gt;&lt;b&gt;Version:&lt;/b&gt; 1.0</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">initPinyin</span><span class="params">(String filePath)</span> <span class="keyword">throws</span> FileNotFoundException, UnsupportedEncodingException </span>&#123;</span><br><span class="line">		<span class="comment">// 读取多音字的全部拼音表;</span></span><br><span class="line">		InputStreamReader isr = <span class="keyword">new</span> InputStreamReader(<span class="keyword">new</span> FileInputStream(filePath), <span class="string">"gbk"</span>);</span><br><span class="line">		BufferedReader br = <span class="keyword">new</span> BufferedReader(isr);</span><br><span class="line">		String s = <span class="keyword">null</span>;</span><br><span class="line">		<span class="keyword">try</span> &#123;</span><br><span class="line">			<span class="keyword">while</span> ((s = br.readLine()) != <span class="keyword">null</span>) &#123;</span><br><span class="line">				<span class="keyword">if</span> (s != <span class="keyword">null</span>) &#123;</span><br><span class="line">					String[] arr = s.split(<span class="string">"#"</span>);</span><br><span class="line">					String pinyin = arr[<span class="number">0</span>];</span><br><span class="line">					String chinese = arr[<span class="number">1</span>];</span><br><span class="line">					<span class="keyword">if</span> (chinese != <span class="keyword">null</span>) &#123;</span><br><span class="line">						String[] strs = chinese.split(<span class="string">" "</span>);</span><br><span class="line">						List&lt;String&gt; list = Arrays.asList(strs);</span><br><span class="line">						pinyinMap.put(pinyin, list);</span><br><span class="line">					&#125;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">			<span class="keyword">try</span> &#123;</span><br><span class="line">				br.close();</span><br><span class="line">			&#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">				e.printStackTrace();</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="2-新建一个duoyinzi-dict-txt-字典文件，可按照需求自己定义-，文件内容如下"><a href="#2-新建一个duoyinzi-dict-txt-字典文件，可按照需求自己定义-，文件内容如下" class="headerlink" title="2.新建一个duoyinzi_dict.txt(字典文件，可按照需求自己定义)，文件内容如下"></a>2.新建一个duoyinzi_dict.txt(字典文件，可按照需求自己定义)，文件内容如下</h5><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br></pre></td><td class="code"><pre><span class="line">a#阿 阿姨 阿富 阿门 阿拉 阿林  黑阿  麦阿密 鹿城阿岙 阿福  </span><br><span class="line">ao#拗口 违拗 凹  </span><br><span class="line">ai#艾 艾滋 艾蒿 未艾  </span><br><span class="line">bang#膀 翅膀 臂膀 重磅 磅秤 黄泥磅店 蛤蚌 蚌壳 河蚌 鹬蚌 珠蚌 蚌  </span><br><span class="line">ba#扒  </span><br><span class="line">bai#叔伯 百 百万  柏  </span><br><span class="line">bao#剥皮 薄 超薄 薄脆 薄板 薄饼  暴 暴晒 暴发 暴雨 暴力 风暴  暴露 暴风  汉堡 古堡 地堡 城堡 龍堡 卡斯堡  麻家堡 麦芬堡 汉堡 麦得堡  麦尔堡  曝光 瀑河  </span><br><span class="line">beng#蚌埠  </span><br><span class="line">bi#复辟  臂 臂章 螳臂 交臂 前臂 一臂 奋臂 膀臂 臂膀 秘鲁 泌阳  </span><br><span class="line">bing#屏弃 屏气 屏除 屏退 屏息  </span><br><span class="line">bian#扁 扁桃 便 方便 方便面 便当 便捷  </span><br><span class="line">bo#薄 薄荷 单薄 伯 伯仲 伯乐 伯劳 伯父 大伯 老伯 伯母 黄伯 伯爵 停泊 淡泊 尼泊 漂泊 波 鸿波 柏林  </span><br><span class="line">bu#大埔  </span><br><span class="line">can#参 参谋 参事 总参 参数 参议 参观 参拜 参股  </span><br><span class="line">cang#藏 埋藏 藏头 秘藏  雪藏 藏匿 收藏 馆藏 矿藏 隐藏  蕴藏 藏袍 储藏 窖藏 藏龙  藏胞 冷藏 珍藏 私藏 藏掖 西藏 藏书 藏品 伧俗  伧 龙藏寺  </span><br><span class="line">cen#参差  </span><br><span class="line">ceng#曾 不曾 似曾 几曾 何曾 曾经 曾几 未曾 噌  噌的 一声  </span><br><span class="line">cha#差  刹那 宝刹 一刹  喳喳  </span><br><span class="line">chai#公差 差役 专差 官差 听差 美差 办差 差事 差使 肥差 当差 钦差  </span><br><span class="line">chan#颤 颤悠  单于 禅 禅学 班禅 禅宗 禅堂 禅门 禅机 禅杖 禅房 禅师 坐禅 参禅 禅院  </span><br><span class="line">chang#长 周长 细长 长发 三长 长河 长袖 长衫 天长 长短 超长 长沙 长春 长远 长度 长江 长处 长假  长街 长征 全长 长城 波长  身长 长途 长吁 长虹 长方  厂  </span><br><span class="line">chao#朝 朝阳 朝阳区 朝鲜 朝廷 王朝 历朝 解嘲 讥嘲 自嘲 嘲笑 嘲弄 冷嘲 嘲讽 绰绰 绰起 绰家 剿袭 剿说  </span><br><span class="line">che#车 汽车 停车场 车车  黑车 车饰  </span><br><span class="line">chen#称职 匀称 称心 相称 对称  </span><br><span class="line">cheng#称 职称 简称 总称 官称 代称 称号 称谓  昵称 谦称 全称 名称  乘 噌吰 澄  </span><br><span class="line">chu#六畜 家畜 耕畜 畜生 牲畜  </span><br><span class="line">chui#椎心  </span><br><span class="line">chuan#传 文传 传媒 传销 传情 真传 祖传 传闻 传家 秘传 传单 传说  </span><br><span class="line">chi#匙子 茶匙 羹匙 汤匙 尺 尺度 英尺 咫尺 尺码 公尺 卡尺 米尺 卷尺  </span><br><span class="line">chong#重庆 重重  </span><br><span class="line">chou#臭 汗臭 臭氧 口臭 腋臭 臭虫 臭骂 臭美 酸臭 腐臭 臭气 腥臭 臭名 遗臭 恶臭 臭豆 狐臭 臭味 臭架  </span><br><span class="line">chuang#经幢  </span><br><span class="line">chuo#绰 绰约 阔绰 绰号 宽绰  </span><br><span class="line">ci#参差 伺候 龟兹  </span><br><span class="line">cuan#攒钱 攒聚 攒动   </span><br><span class="line">cuo#撮儿 撮要 撮合  </span><br><span class="line">da#大 大街 沓子 龙大 大西洋 大昌  大圣 福大 黑大 大华 大包  大厦  </span><br><span class="line">dao#叨 叨唠 絮叨 叨念 叨咕 念叨 唠叨 叨叨 磨叨  </span><br><span class="line">dai#大夫  </span><br><span class="line">dan#单 西单 东单 清单 报单 单利 名单 单姓 单亲 单线 单科 单间 单挑 单价 单词  子弹    </span><br><span class="line">de#的 似的 总的 中的 别的  </span><br><span class="line">deng#澄清  </span><br><span class="line">di#怎的 无的 有的 目的 标的 打的 的确 的当 的士 上地 大地 天地 提防 堤  </span><br><span class="line">diao#调 蓝调 蓝调吧 调调 音调 论调 格调 调令 低调 笔调 基调 强调 声调 滥调 老调 色调 单调 腔调 跑调 曲调 步调 语调 主调 情调  </span><br><span class="line">du#都 都会 国都 都城 古都 故都 大都 首都 成都 旧都 都市 龙都  鼎都 鹤都 鹏都 鸿都  麦度 度 态度 读书 法度 宽度 进度   </span><br><span class="line">dui#堆    </span><br><span class="line">dou#全都 句读  </span><br><span class="line">duo#测度 忖度 揣度 猜度 舵  </span><br><span class="line">dun#粮囤 顿  </span><br><span class="line">e#阿谀 阿胶 阿弥 恶心  </span><br><span class="line">er#儿  </span><br><span class="line">fan#番 番茄 繁  </span><br><span class="line">fo#佛 佛塔 佛徒 佛牙 佛教  </span><br><span class="line">fu#仿佛 果脯  </span><br><span class="line">fou#否 是否 与否  </span><br><span class="line">ga#咖 咖喱 伽马  </span><br><span class="line">gai#盖  </span><br><span class="line">gang#扛鼎  </span><br><span class="line">ge#革 革命  皮革  鹰革  蛤蚧 文蛤 蛤蜊 咯吱 咯噔 咯咯  </span><br><span class="line">gei#给  </span><br><span class="line">geng#脖颈  </span><br><span class="line">gong#女红  </span><br><span class="line">gu#谷 布谷 谷物 谷地 硅谷 中鹄  麦谷 麓谷 鹭谷 鼓  </span><br><span class="line">gui#龟 龟山 龟士 龟博 龟仔 鹿龟  龟汁 龟苓 龟顶  </span><br><span class="line">gua#挺括 顶呱 呱呱 呱唧 呱嗒 呱  </span><br><span class="line">guan#纶巾 东莞  </span><br><span class="line">guang#广 广州 广东 广播  </span><br><span class="line">ha#蛤蟆 癞蛤 虾蟆  </span><br><span class="line">hai#还是 还有 咳  </span><br><span class="line">hao#貉子 貉绒  </span><br><span class="line">hang#总行 分行 支行 行业 排行 行情 央行 商行 外行 银行 商行 酒行 麻行 琴行 巷道 珩  </span><br><span class="line">he#和 嘉和 和睦 亲和  龙和  之貉 威吓 恫吓 恐吓 鼎和  锦和 麒和苑 合 合资 鸿合  </span><br><span class="line">heng#道行  </span><br><span class="line">hu#鹄 鹄望 鸿鹄 鹄立  </span><br><span class="line">huan#还 鹂还  </span><br><span class="line">hui#会 会馆 会展 会所 协会 国会 会堂  </span><br><span class="line">hong#红 红装 红牌  红木 红人 虹  </span><br><span class="line">huo#软和 热和 暖和  </span><br><span class="line">ji#病革 给养 自给 给水 薪给 给予 供给 稽考 稽查 稽核 滑稽 稽留 缉获 缉查 缉私 缉捕 狼藉 奇数 亟  亟待 亟须 亟亟 亟需 诘屈 荠菜  </span><br><span class="line">jia#雪茄 伽  瑜伽 伽利略 家  </span><br><span class="line">jian#见 龙见  </span><br><span class="line">jiang#降 降温 降低 降旗 下降 倔强  </span><br><span class="line">jiao#嚼舌 嚼子 细嚼 角 平角 视角 海角 龙角 鹿角  围剿 征剿 饺 饺子 脚  </span><br><span class="line">jie#解 解放 慰藉 蕴藉 盘诘 诘难 诘问 反诘 桔  </span><br><span class="line">jin#矜 矜夸 矜持 骄矜 自矜 劲  </span><br><span class="line">jing#颈 颈项 颈椎 引颈 长颈 宫颈 瓶颈 龙颈  黑颈鹤 鹿颈  景 景色 帝景 劲松  </span><br><span class="line">ju#咀 咀嚼  居  桔汁  </span><br><span class="line">jun#均 平均 鸿均  </span><br><span class="line">juan#棚圈 圈养  </span><br><span class="line">jv#咀嚼 趑趄  </span><br><span class="line">jvan#猪圈 羊圈  </span><br><span class="line">jue#主角 角色 旦角 女角 丑角 角力 名角 配角 咀嚼 觉 直觉 感觉 错觉 触觉 幻觉 堀  </span><br><span class="line">jun#龟裂 俊  </span><br><span class="line">jvn#龟裂  </span><br><span class="line">ka#咖啡 卡 磁卡  贺卡 卡拉 胸卡 声卡 卡片  绿卡 卡通  网卡 卡口  龙卡  咯痰 咯血 喀  </span><br><span class="line">kang#扛  </span><br><span class="line">ke#咳 咳嗽 干咳 贝壳 蚌壳 外壳 蛋壳 脑壳 弹壳  </span><br><span class="line">keng#吭声 吭气 吭哧  </span><br><span class="line">kuai#会计 财会  </span><br><span class="line">kuo#括  </span><br><span class="line">la#癞痢 腊  </span><br><span class="line">lai#癞疮 癞子 癞蛤 癞皮  </span><br><span class="line">lao#积潦 络子 落枕 落价 麻粩  </span><br><span class="line">le#乐 娱乐 玩乐 乐趣  美乐 乐缘  勒  了  </span><br><span class="line">lei#勒紧  </span><br><span class="line">lo#然咯  </span><br><span class="line">lou#佝偻  </span><br><span class="line">long#里弄 弄堂 泷  </span><br><span class="line">li#礼 豊 栎  </span><br><span class="line">liao#了解 了结  明了 了得 末了 未了 了如  了如指掌 潦草 潦倒  </span><br><span class="line">liang#靓  </span><br><span class="line">liu#碌碡  碌碌 劳碌 忙碌 庸碌 六  </span><br><span class="line">lu#绿林 碌  </span><br><span class="line">luo#络 络腮 落 部落 落花 日落  </span><br><span class="line">lv#率 频率 机率 比率 效率 胜率 概率 汇率 功率 倍率 绿 绿叶 淡绿 绿色 绿豆 伛偻  绿洲  </span><br><span class="line">lun#丙纶 锦纶 经纶 涤纶  </span><br><span class="line">mai#埋  </span><br><span class="line">man#埋怨 蔓  </span><br><span class="line">mai#脉 山脉 动脉 命脉 筋脉 脉象 气脉 脉动 脉息 脉络 一脉 经脉  </span><br><span class="line">mang#氓 流氓  </span><br><span class="line">me#黛么  </span><br><span class="line">meng#群氓 盟  </span><br><span class="line">mei#没  </span><br><span class="line">mo#埋没 隐没 脉脉 模 航模 模糊 男模 楷模 规模 劳模 模型 模范 模特 名模  摩 么 麼 麽  </span><br><span class="line">mou#绸缪  </span><br><span class="line">mi#秘 秘密 秘方 奥秘 神秘 泌尿 分泌  </span><br><span class="line">miu#谬 谬论 纰缪  </span><br><span class="line">mu#人模 字模 模板 模样 模具 装模 装模做样 模子  </span><br><span class="line">na#哪 娜 安娜 娜娜 丽娜 黛尔娜 黛娜  海娜 黑娜 黄丽娜 麦香娜  优娜 麦娜 麟娜  那  </span><br><span class="line">nan#南 南方 湖南  </span><br><span class="line">ne#哪吒 呢  </span><br><span class="line">nong#弄  </span><br><span class="line">ni#毛呢 花呢 呢绒 线呢 呢料 呢子 呢喃 溺  </span><br><span class="line">niao#便溺 尿  </span><br><span class="line">nian#粘  </span><br><span class="line">niu#执拗 拗不  </span><br><span class="line">nue#疟 疟疾  </span><br><span class="line">nuo#婀娜 袅娜  </span><br><span class="line">nv#女 女人  </span><br><span class="line">nve#疟原 疟蚊  </span><br><span class="line">pa#扒  </span><br><span class="line">pai#迫击 迫击炮 派  </span><br><span class="line">pao#刨 炮  </span><br><span class="line">pang#膀胱 膀肿 磅礴  </span><br><span class="line">pi#否极 臧否 龙陂 黄陂  </span><br><span class="line">pian#扁舟 便宜  </span><br><span class="line">piao#朴姓  </span><br><span class="line">ping#屏  屏幕 荧屏 银屏  </span><br><span class="line">po#泊 迫 朴刀 坡 陂  </span><br><span class="line">pu#暴十 一曝十寒 里堡 十里堡 胸脯 肉脯 脯子 杏脯 简朴 朴质 古朴 朴厚 纯朴 朴素 诚朴 俭朴 朴实 淳朴 曝晒 瀑布 飞瀑 埔 黄埔  </span><br><span class="line">qiu#龟兹  </span><br><span class="line">qi#稽首 缉鞋 栖 奇 奇妙 传奇 亟来 荸荠 蹊跷  林栖  鹿奇 鹭奇 漆 齐 齐天大圣 齐天 其  </span><br><span class="line">qia#卡脖 卡子 关卡 卡壳 哨卡 边卡 发卡  </span><br><span class="line">qiao#雀盲 雀子 地壳 甲壳 躯壳  </span><br><span class="line">qian#纤手 拉纤 纤夫 纤绳 乾  </span><br><span class="line">qiang#强颜  强人 自强 强烈 强风 强大 黎强 麒强 鹤强 龚强  </span><br><span class="line">qie#茄子 颠茄 番茄 趔趄   </span><br><span class="line">qin#亲 亲和 亲亲 棘矜 矜锄  </span><br><span class="line">qing#干亲 亲家 黥  </span><br><span class="line">qu#区 小区  </span><br><span class="line">quan#转圈 钢圈 圆圈 罗圈 弧圈 垫圈 小圈 眼圈  </span><br><span class="line">que#雀 麻雀 鸟雀 燕雀 孔雀 云雀 雀巢、  </span><br><span class="line">re#般若  </span><br><span class="line">ruo#若  </span><br><span class="line">sai#塞 麦迪塞姆 活塞  </span><br><span class="line">se#堵塞 搪塞 茅塞 闭塞 鼻塞 梗塞 阻塞 淤塞 拥塞 哽塞 月色 彩色 特色 深色 声色 黛色  黛色 黑色瞳 色坊  </span><br><span class="line">sha#刹车 急刹 急刹车 厦  广厦 大厦 商厦 鹰大厦  莎  </span><br><span class="line">shai#色子  </span><br><span class="line">shan#姓单 单县  杉 铁杉 杉树 封禅 禅让 黒杉  栅  </span><br><span class="line">shang#裳 衣裳  </span><br><span class="line">she#拾级 折本  </span><br><span class="line">shen#沙参 野参 参王 人参 红参 丹参 山参 海参 刺参 没什 什么 为什 鹿参 身  </span><br><span class="line">sheng#野乘 千乘 史乘  省 晟 盛 盛大 鸿盛  </span><br><span class="line">shi#钥匙 拾荒 捡拾 拾物 家什 什物 什锦 麻什  麦什 喀什 牛什  识  见识 知识 似的 骨殖 食 饮食 副食  石 石业 石头 石艺 氏 姓氏 上栅 下栅  </span><br><span class="line">shuai#表率 率性 率直 率真 粗率 率领 轻率 直率 草率 大率 坦率 数字 招数 基数 数码  </span><br><span class="line">shuang#泷水  </span><br><span class="line">shu#属 金属 气数 岁数 度数 数据 级数 数控 数学 参数 次数 正数 代数 实数 系数 分数 辈数  </span><br><span class="line">shui#游说  </span><br><span class="line">shuo#数见 数见不鲜 传说 听说 妄说 实说  胡说 评说 分说 小说  </span><br><span class="line">si#窥伺 伺弄 伺机 疑似 似是 好似 似曾 形似 酷似 貌似 似懂 胜似 恰似 近似 神似 赛似 看似 活似 强似 似乎 类似 相似 思  </span><br><span class="line">su#宿主 宿命 归宿 住宿 借宿 寄宿 宿营 夜宿 露宿 投宿 宿舍 名宿 整宿 食宿  </span><br><span class="line">sui#尿泡  </span><br><span class="line">ta#拓本 拓片 碑拓 疲沓 拖沓 杂沓 沓 塔 鸿塔  </span><br><span class="line">tang#汤 鸭汤 鸡汤  </span><br><span class="line">tao#叨扰 叨光 陶 陶器  </span><br><span class="line">tan#弹性 弹力 反弹  </span><br><span class="line">ti#手提 提速 提意 提前 提早 提升 提议 提款 提婚 提包 耳提 提供 麦麦提 体  </span><br><span class="line">tiao#空调 调教 烹调 调羹 调料 调皮  调控 调节 调整 调价 谐调  协调 调色 调侃 调味 失调 调治 调频 调剂 调停 调休 调解  </span><br><span class="line">ting#町 域町 听  </span><br><span class="line">tong#垌  </span><br><span class="line">tui#褪色 褪毛  </span><br><span class="line">tuo#拓 拓宽 拓荒 开拓 落拓 拓展 拓印  </span><br><span class="line">tun#屯 囤积 囤聚  </span><br><span class="line">wei#尾 响尾 尾巴 尾灯 船尾 追尾 尾椎 月尾  燕尾 尾数 年尾 岁尾 鸢尾 凤尾 彗尾 尾翼 结尾 遗之 龙尾  齐鑫尾 麻尾 麦度 鹿尾  </span><br><span class="line">wu#可恶 交恶 好恶 厌恶 憎恶 嫌恶 痛恶 深恶  </span><br><span class="line">wan#藤蔓 枝蔓 瓜蔓 蔓儿  莞尔 万 百万 萬  </span><br><span class="line">xia#虾 虾仁 青虾 大虾 虾皮 对虾 虾子 虾酱 虾兵 虾米 龙虾 噶厦 厦门 吓唬 吓人 惊吓 天虾 龙虾 皮皮虾 麦虾  </span><br><span class="line">xi#栖栖 系 关系 星系 水系 系念 体系 联系 系列 菜系 世系  蹊 蹊径 溪 洗  </span><br><span class="line">xiao#校 学校 切削 削面 刀削 刮削  </span><br><span class="line">xian#纤细 光纤 纤巧 纤柔 纤小 纤维 纤瘦 纤纤 化纤 纤秀 棉纤 纤尘  </span><br><span class="line">xiang#巷 街巷 僻巷 巷子 龙门巷 六巷 龙湾巷 龙港巷 龙泉巷 龙巷 龙妙巷 龄巷 齐家巷 鼓楼巷 鼓巷 黎明巷 麻子巷 麻园巷 麦子巷 鹊巷  </span><br><span class="line">xie#解数 出血 采血 换血 血糊 尿血 淤血 放血 血晕 血淋 便血 吐血 咯血 叶韵 蝎 蝎子  </span><br><span class="line">xiu#铜臭 乳臭 成宿 星宿  </span><br><span class="line">xin#馨 信 鸿信  </span><br><span class="line">xing#深省 省视 内省 不省人事 省悟 省察 行 旅行 例行 行程 行乐 龙行 人行 流行 先行 行星 品行  发行 行政 风行 龙行 龍行 麟行  </span><br><span class="line">xu#牧畜 畜产 畜牧 畜养 吁 气吁 喘吁 吁吁 麦埂圩  </span><br><span class="line">xue#削 削减 削弱  削瘦 削球 削平 削价 瘦削 剥削 削职  删削 削肩  血 吸血  </span><br><span class="line">xun#荨 荨麻 荨麻疹  </span><br><span class="line">ya#芽  </span><br><span class="line">yao#发疟 疟子 约斤 称约 钥匙 金钥 耀  </span><br><span class="line">yan#吞咽 咽气 咽喉  殷红 腌 腌制 腌肉 腌菜 烟 烟草 名烟 烟酒  </span><br><span class="line">ye#抽咽 哽咽 咽炎 下咽 呜咽 幽咽 悲咽 叶 绿叶 叶子 荷叶 落叶 菜叶 红叶 树叶 枫叶  茶叶 葉 鸿葉  液   </span><br><span class="line">yi#自艾 惩艾 后尾 遗  屹  </span><br><span class="line">yin#殷 殷勤 殷墟 殷切 殷鉴  </span><br><span class="line">yo#杭育  </span><br><span class="line">yu#谷浑 呼吁 吁请 吁求 育 体育 教育 育儿 熨帖 熨烫 於  </span><br><span class="line">yuan#员  </span><br><span class="line">yun#熨 熨斗 电熨斗  </span><br><span class="line">yue#乐音 器乐 乐律 乐章 音乐 乐理 民乐 乐队 声乐 奏乐 弦乐 乐坛 管乐 配乐 乐曲 乐谱  锁钥 密钥 乐团 鼓乐社 乐器 栎阳 约 约会  </span><br><span class="line">zan#积攒  </span><br><span class="line">zang#宝藏 藏历 藏文 藏香 藏语 藏青 藏族 藏医 藏戏 藏药 藏蓝 蔵  </span><br><span class="line">ze#择 择善  </span><br><span class="line">zeng#曾孙 曾祖  </span><br><span class="line">za#绑扎 结扎 包扎 捆扎  </span><br><span class="line">zai#牛仔 龟仔 龙仔 鼻仔 羊仔  仔仔 麻仔  麵包仔 麦旺仔 鸿仔 煲仔 福仔  </span><br><span class="line">zha#扎 马扎 挣扎 扎啤 扎根 扎手 扎针 扎花 扎堆 扎营 扎实 稳扎 柞水 麻扎镇 麻扎乡 喳 栅栏  </span><br><span class="line">zhai#择菜  </span><br><span class="line">zhan#不粘 粘贴 粘连  </span><br><span class="line">zhao#朝朝 明朝 朝晖 朝夕 朝思 有朝 今朝 朝气 朝三 朝秦 朝霞 鹰爪 龙爪 魔爪 爪牙 失着 着数 龙爪槐  </span><br><span class="line">zhe#折 破折 打折 叠 曲折 折冲 存折  折合 折旧 折纸 骨折 折返 折价 折算 波折 折扇 对折 不折 折扣 七折 折中 拙著 要著 著文 新著 着 本着 对着  </span><br><span class="line">zhi#标识 嘎吱 咯吱 吱扭 吱吱 繁殖 增殖 养 生殖 殖民 枝  </span><br><span class="line">zhong#重 重量 鹏重 种  </span><br><span class="line">zhou#粥  </span><br><span class="line">zhu#属意 著录 撰著 名著 专著 著述 著作 显著 昭著 原著 著名 著书 遗著 论著 著者 编著 卓著 译著 著称  </span><br><span class="line">zhua#爪  </span><br><span class="line">zhui#椎 椎骨 尾椎 椎间 腰椎 胸椎 颈椎 脊椎  </span><br><span class="line">zhuo#执著 着装 着落 着意 着力 附着 着笔 胶着 着手 着重 穿着 衣着 执着 着眼 着墨 着实 沉着 着陆 着想 着色  </span><br><span class="line">zhuang#幢房 一幢 幢楼  </span><br><span class="line">zi#吱声 兹 来兹 今兹 仔细 仔猪  </span><br><span class="line">zu#足 沐足 足道  </span><br><span class="line">zuo#撮毛 小撮 柞绸 柞蚕 柞树 柞木  </span><br><span class="line">zui#咀唇 尖沙咀 黄达咀 黄土咀 鹰咀</span><br></pre></td></tr></table></figure>
<h5 id="运行，完美解决。。。。。"><a href="#运行，完美解决。。。。。" class="headerlink" title="运行，完美解决。。。。。"></a>运行，完美解决。。。。。</h5><p>demo下载地址：<br>链接：<a href="https://pan.baidu.com/s/1o8LwXPw" target="_blank" rel="noopener">https://pan.baidu.com/s/1o8LwXPw</a> 密码：tbt0<br>链接失效的话请联系本人。。。。</p>
<p>github:<a href="https://github.com/KongGaoDeNiao/PinyinDuoYinzi" target="_blank" rel="noopener">https://github.com/KongGaoDeNiao/PinyinDuoYinzi</a></p>
<p>参考链接：<br><a href="http://blog.csdn.net/hao_kkkkk/article/details/51780719" target="_blank" rel="noopener">http://blog.csdn.net/hao_kkkkk/article/details/51780719</a><br><a href="https://zhidao.baidu.com/question/488199891043049572.html" target="_blank" rel="noopener">https://zhidao.baidu.com/question/488199891043049572.html</a></p>

          
        
      
    </div>
    
    
    

	<div>
		
	</div>
	<div>
		
	</div>
    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://cnsyear.com/2017/07/13/Tomcat配置访问、启动日志/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="趙小傑~～">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="CNSYEAR BLOG'S">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/07/13/Tomcat配置访问、启动日志/" itemprop="url">Tomcat配置访问、启动日志</a></h1>
        

        <div class="post-meta">
		 
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-07-13T15:51:36+08:00">
                2017-07-13
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Tomcat/" itemprop="url" rel="index">
                    <span itemprop="name">Tomcat</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>Tomcat配置访问、启动日志</p>
</blockquote>
<h4 id="访问日志"><a href="#访问日志" class="headerlink" title="访问日志"></a>访问日志</h4><p>该日志默认不开启 修改/conf/server.xml</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--这里配置的是localhost域名的访问日志--&gt;</span><br><span class="line">&lt;Host name=<span class="string">"localhost"</span>  appBase=<span class="string">"webapps"</span></span><br><span class="line">    unpackWARs=<span class="string">"true"</span> autoDeploy=<span class="string">"true"</span></span><br><span class="line">    xmlValidation=<span class="string">"false"</span> xmlNamespaceAware=<span class="string">"false"</span>&gt;</span><br><span class="line"></span><br><span class="line">&lt;Valve className=<span class="string">"org.apache.catalina.valves.AccessLogValve"</span> directory=<span class="string">"logs"</span>  </span><br><span class="line">       prefix=<span class="string">"localhost_access_log."</span> suffix=<span class="string">".txt"</span> pattern=<span class="string">"common"</span> resolveHosts=<span class="string">"false"</span>/&gt;</span><br><span class="line"></span><br><span class="line">&lt;/Host&gt;</span><br></pre></td></tr></table></figure>
<h4 id="启动日志"><a href="#启动日志" class="headerlink" title="启动日志"></a>启动日志</h4><p>该日志默认开启 conf/logging.properties </p>
<p>问题：启动start.bat发现log文件夹中没有生成相应的日志</p>
<ul>
<li>排查最后找出问题所在，问题是在tomcat下的bin目录下的catalina.bat文件内容被修改到了，影响了日志的输出，看了里面的内容发现之前修改内存大小时动到了catalina.bat，在catalina.bat文件里的</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">## 设置了内存大小</span><br><span class="line">set JAVA_OPTS=-server -Xms1024m -Xmx1024m -XX:PermSize=<span class="number">256</span>M -XX:MaxNewSize=<span class="number">512</span>m -XX:MaxPermSize=<span class="number">256</span>m -Djava.awt.headless=<span class="keyword">true</span></span><br></pre></td></tr></table></figure>
<p>把上面设置内存大小后，导致没有日志输出。<br>应该如下设置：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set JAVA_OPTS=%JAVA_OPTS% -server -Xms1024m -Xmx1024m -XX:PermSize=<span class="number">256</span>M -XX:MaxNewSize=<span class="number">512</span>m -XX:MaxPermSize=<span class="number">256</span>m -Djava.awt.headless=<span class="keyword">true</span></span><br></pre></td></tr></table></figure>
<p>%JAVA_OPTS%得把这个加上，否则找不到路径</p>

          
        
      
    </div>
    
    
    

	<div>
		
	</div>
	<div>
		
	</div>
    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://cnsyear.com/2017/07/13/Tomcat生产环境的性能调优/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="趙小傑~～">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="CNSYEAR BLOG'S">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/07/13/Tomcat生产环境的性能调优/" itemprop="url">Tomcat生产环境的性能调优</a></h1>
        

        <div class="post-meta">
		 
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-07-13T15:34:33+08:00">
                2017-07-13
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Tomcat/" itemprop="url" rel="index">
                    <span itemprop="name">Tomcat</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>Tomcat生产环境的性能调优</p>
</blockquote>
<h4 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h4><p>java.lang.OutOfMemoryError: Java heap space —-JVM Heap（堆）溢出</p>
<p>工作时第一次遇见这个错误，很慌张因为客户那边网站无法访问了。出现的原因就是Tomcat配置的内存太小，访问量大的时候内存就溢出了。</p>
<p>天津项目考生查询会有短时间出现大量用户访问，这时就会有并发瓶颈。</p>
<h4 id="Tomcat性能优化一：内存的优化"><a href="#Tomcat性能优化一：内存的优化" class="headerlink" title="Tomcat性能优化一：内存的优化"></a>Tomcat性能优化一：内存的优化</h4><p>Tomcat默认可以使用的内存为128M o(╥﹏╥)o这点够干啥的！</p>
<p>在bin/catalina.bat或bin/catalina.sh 配置文件中进行。windows上，在catalina.bat中添加：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set JAVA_OPTS=%JAVA_OPTS% -server -Xms1024m -Xmx1024m -XX:PermSize=<span class="number">256</span>M -XX:MaxNewSize=<span class="number">512</span>m -XX:MaxPermSize=<span class="number">256</span>m -Djava.awt.headless=<span class="keyword">true</span></span><br></pre></td></tr></table></figure>
<p>相关参数：</p>
<ul>
<li>JAVA_OPTS参数说明 <ul>
<li>-server 启用jdk 的 server 版； </li>
<li>-Xms java虚拟机初始化时的最小内存； </li>
<li>-Xmx java虚拟机可使用的最大内存； #-Xms与-Xmx设成一样的值，避免JVM因为频繁的GC导致性能大起大落</li>
<li>-XX:PermSize 内存永久保留区域 </li>
<li>-XX:MaxPermSize 内存最大永久保留区域</li>
<li>-XX:MaxNewSize 对自身堆栈的新的最大的分配；当tomcat内存不足时，调用此分配；</li>
<li>-Djava.awt.headless=true 这个参数下面单独解释↓↓↓
　　</li>
</ul>
</li>
<li>java.awt.headless 模式<ul>
<li>什么是 java.awt.headless？Headless模式是系统的一种配置模式。在该模式下，系统缺少了显示设备、键盘或鼠标。</li>
<li>何时使用和headless mode？Headless模式虽然不是我们愿意见到的，但事实上我们却常常需要在该模式下工作，尤其是服务器端程序开发者。因为服务器（如提供Web服务的主机）往往可能缺少前述设备，但又需要使用他们提供的功能，生成相应的数据，以提供给客户端（如浏览器所在的配有相关的显示设备、键盘和鼠标的主机）。</li>
<li>如何使用和Headless mode？<br>一般是在程序开始激活headless模式，告诉程序，现在你要工作在Headless  mode下，就不要指望硬件帮忙了，你得自力更生，依靠系统的计算能力模拟出这些特性来:<br>System.setProperty(“java.awt.headless”, “true”);</li>
<li>JAVA程序在浏览器中显示打印报表pdf文档时，报如下错误：<br>JasperReports encountered this error : Can’t connect to X11 window server using ‘:0.0’ as the value of the DISPLAY variable.<br>或者JasperReports encountered this error : sun/awt/X11GraphicsEnvironment</li>
<li>解决办法是<br>运行时加上-Djava.awt.headless=true</li>
</ul>
</li>
</ul>
<h4 id="Tomcat性能优化二：并发优化"><a href="#Tomcat性能优化二：并发优化" class="headerlink" title="Tomcat性能优化二：并发优化"></a>Tomcat性能优化二：并发优化</h4><p>1.调整连接器connector的并发处理能力，在Tomcat 配置文件 server.xml 中的</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;Connector port=<span class="string">"9027"</span></span><br><span class="line">　　protocol=<span class="string">"HTTP/1.1"</span></span><br><span class="line">　　maxHttpHeaderSize=<span class="string">"8192"</span></span><br><span class="line">　　maxThreads=<span class="string">"1000"</span></span><br><span class="line">　　minSpareThreads=<span class="string">"100"</span></span><br><span class="line">　　maxSpareThreads=<span class="string">"1000"</span></span><br><span class="line">　　minProcessors=<span class="string">"100"</span></span><br><span class="line">　　maxProcessors=<span class="string">"1000"</span></span><br><span class="line">　　enableLookups=<span class="string">"false"</span></span><br><span class="line">　　URIEncoding=<span class="string">"utf-8"</span></span><br><span class="line">　　acceptCount=<span class="string">"1000"</span></span><br><span class="line">　　redirectPort=<span class="string">"8443"</span></span><br><span class="line">　　disableUploadTimeout=<span class="string">"true"</span>/&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>参数说明<ul>
<li>maxThreads 客户请求最大线程数 </li>
<li>minSpareThreads Tomcat初始化时创建的 socket 线程数 </li>
<li>maxSpareThreads Tomcat连接器的最大空闲 socket 线程数 </li>
<li>enableLookups 若设为true, 则支持域名解析，可把 ip 地址解析为主机名 </li>
<li>redirectPort 在需要基于安全通道的场合，把客户请求转发到基于SSL 的 redirectPort 端口 </li>
<li>acceptAccount 监听端口队列最大数，满了之后客户请求会被拒绝（不能小于maxSpareThreads ） </li>
<li>connectionTimeout 连接超时 </li>
<li>minProcessors 服务器创建时的最小处理线程数 </li>
<li>URIEncoding URL统一编码</li>
</ul>
</li>
</ul>
<p>2.Tomcat缓存优化</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&lt;Connector port=<span class="string">"9027"</span></span><br><span class="line">　　protocol=<span class="string">"HTTP/1.1"</span></span><br><span class="line">　　maxHttpHeaderSize=<span class="string">"8192"</span></span><br><span class="line">　　maxThreads=<span class="string">"1000"</span></span><br><span class="line">　　minSpareThreads=<span class="string">"100"</span></span><br><span class="line">　　maxSpareThreads=<span class="string">"1000"</span></span><br><span class="line">　　minProcessors=<span class="string">"100"</span></span><br><span class="line">　　maxProcessors=<span class="string">"1000"</span></span><br><span class="line">　　enableLookups=<span class="string">"false"</span></span><br><span class="line">　　compression=<span class="string">"on"</span></span><br><span class="line">　　compressionMinSize=<span class="string">"2048"</span></span><br><span class="line">　　compressableMimeType=<span class="string">"text/html,text/xml,text/javascript,text/css,text/plain"</span></span><br><span class="line">　　connectionTimeout=<span class="string">"20000"</span></span><br><span class="line">　　URIEncoding=<span class="string">"utf-8"</span></span><br><span class="line">　　acceptCount=<span class="string">"1000"</span></span><br><span class="line">　　redirectPort=<span class="string">"8443"</span></span><br><span class="line">　　disableUploadTimeout=<span class="string">"true"</span>/&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>参数说明<ul>
<li>compression 打开压缩功能 </li>
<li>compressionMinSize 启用压缩的输出内容大小，这里面默认为2KB </li>
<li>compressableMimeType 压缩类型 </li>
<li>connectionTimeout 定义建立客户连接超时的时间. 如果为 -1, 表示不限制建立客户连接的时间</li>
</ul>
</li>
</ul>
<p>以上仅是工作中遇到的优化的方案，对应单一服务来说不管怎么优化总是有性能瓶颈的。 </p>

          
        
      
    </div>
    
    
    

	<div>
		
	</div>
	<div>
		
	</div>
    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/6/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/6/">6</a><span class="page-number current">7</span>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/1.jpg" alt="趙小傑~～">
            
              <p class="site-author-name" itemprop="name">趙小傑~～</p>
              <p class="site-description motion-element" itemprop="description">I MISS YOU.</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">65</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">33</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">33</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/cnsyear" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:820382480@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://linuxtools-rst.readthedocs.io/zh_CN/latest/" title="Linux教程" target="_blank">Linux教程</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://ke.qq.com/" title="腾讯课堂" target="_blank">腾讯课堂</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heartbeat"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">趙小傑~～</span>

  
</div>




  <div class="powered-by">
	<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
		  本站访客数:<span id="busuanzi_value_site_uv"></span>
	</span>
  </div>
  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共37.3k字</span>
</div>

<!--51La统计-->
<div style="display:none">
	<script type="text/javascript" src="https://js.users.51.la/19388993.js"></script>
</div>
        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  













  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  

  

  

  
  <!-- 页面点击小红心，在末尾添加，避免找不到 -->
  <script type="text/javascript" src="/js/src/love.js"></script>
  <!--看板娘-->
  <script src="/live2d-widget/autoload.js"></script>

</body>
</html>
